#include <cstdlib>
#include <iostream>
#include <list>
#include <string>

#include "server_Servidor.h"

void parsearListaPuertos(std::string puertos, std::list<int>* listaPuertos) {
	int puerto;
	std::string buffer;

	int indice = 0;
	for (unsigned int i = 0; i < puertos.length(); i++) {
		if (puertos[i] != ',') {
			buffer[indice++] = puertos[i];
		}else {
			puerto = atoi(buffer.c_str());
			listaPuertos->push_back(puerto);

			buffer = "";
			indice = 0;
		}
	}

	puerto = atoi(buffer.c_str());
	listaPuertos->push_back(puerto);
}

int main(int argc, char* argv[]) {
	std::list<int> listaPuertos;

	if (argc < 2) {
		return 0;
	}
	
	parsearListaPuertos(argv[1], &listaPuertos);
	Servidor servidor;

	servidor.iniciar(listaPuertos);

	while (std::cin.get() != 'q') {}

	return servidor.finalizar();
}
